package com.chebaohui.iqs.service.impl.deal.bihu.utils;

import java.security.MessageDigest;
/**
 * 工具类  MD5加密
 * @author yuanxu
 *
 */
public class MD5Util {
  
	private final static String[] heitt={"0","1","2","3","4","5","6","7","8","9","a","b","c","d",
			"e","f"};
    /**
     * 
     * @param b 传入的字节
     * @return 16进制字符串
     */
	private static String get16byte(byte b){
		int n=b;
		if(n < 0){
			n = 256 + n;
		}
		int d1 = n / 16;
		int d2 = n % 16;
		return heitt[d1]+heitt[d2];
	}
     /**
      * 
      * @param bb 传入一个byte数组
      * @return 16进制格式
      */
	private static String get16bytes(byte[] bb){
		StringBuilder sb = new StringBuilder();
		for (byte b : bb) {
			sb.append(get16byte(b));
		}
		return sb.toString();		
	}
    /**
     * 
     * @param incode 传入一个字符串
     * @return md5加密字符串
     */
	public static String getMD5(String incode){
		String outcode=null;
		try {
			MessageDigest md=MessageDigest.getInstance("MD5");
			outcode=get16bytes(md.digest(incode.getBytes("UTF-8")));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return outcode;

	}

}
